import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        StringBuilder sb1 = new StringBuilder("hello");
        StringBuilder sb2 = sb1;
// 追加：即尾插-->字符、字符串、整形数字
        sb1.append(' '); // hello
        sb1.append("world"); // hello world
        sb1.append(123); // hello world123
        System.out.println(sb1); // hello world123
        System.out.println(sb1 == sb2); // true
        System.out.println(sb1.charAt(0)); // 获取0号位上的字符 h
        System.out.println(sb1.length()); // 获取字符串的有效长度14
        System.out.println(sb1.capacity()); // 获取底层数组的总大小
        sb1.setCharAt(0, 'H'); // 设置任意位置的字符 Hello world123
        sb1.insert(0, "Hello world!!!"); // Hello world!!!Hello world123
        System.out.println(sb1);
        System.out.println(sb1.indexOf("Hello")); // 获取Hello第一次出现的位置
        System.out.println(sb1.lastIndexOf("hello")); // 获取hello最后一次出现的位置
        sb1.deleteCharAt(0); // 删除首字符
        sb1.delete(0,5); // 删除[0, 5)范围内的字符
        String str = sb1.substring(0, 5); // 截取[0, 5)区间中的字符以String的方式返回
        System.out.println(str);
        sb1.reverse(); // 字符串逆转
        str = sb1.toString(); // 将StringBuffer以String的方式返回
        System.out.println(str);
    }
    public static void main20(String[] args) {
        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }
    public static void main19(String[] args) {
        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder.append("hello");
        stringBuilder.append(" world");
        String s=stringBuilder.toString();
        System.out.println(s);
    }
    public static void main18(String[] args) {
        String s="hello";
        s+=" world";
        System.out.println(s);
    }
    public static void main17(String[] args) {
        final int array[] = {1,2,3,4,5};
        array[0] = 100;
        System.out.println(Arrays.toString(array));
        //array = new int[]{4,5,6};
    }
    public static void main16(String[] args) {
        String s="   hel l o w  orld   ";
        System.out.println(s);
        String s1=s.trim();
        System.out.println(s1);
    }
    public static void main15(String[] args) {
        String s="abcabcde";
        String s1=s.substring(0,3);
        String s2=s.substring(3);
        System.out.println(s1);
        System.out.println("====");
        System.out.println(s2);
    }
    public static void main14(String[] args) {
        String s="name=zhangsan&age=18";
        String[]strings=s.split("&|=");
        for (int i=0;i< strings.length;i++){
            System.out.println(strings[i]);
        }
    }
    public static void main13(String[] args) {
        String s="name=zhangsan&age=18";
        String[]strings=s.split("&");
        for(int i=0;i<strings.length;i++){
            String[]strings1=strings[i].split("=");
            for (int j=0;j< strings1.length;j++){
                System.out.print(strings1[j]+" ");
            }
            System.out.println();
        }
    }
    public static void main12(String[] args) {
        String str = "192.168.1.1" ;
        String[] result = str.split("\\.") ;
        for(String s: result) {
            System.out.println(s);
        }
    }
    public static void main11(String[] args) {
        String s1="hello world hello world";
        String[]strings=s1.split(" ",2);
        for(String s:strings){
            System.out.println(s);
        }
    }
    public static void main10(String[] args) {
        String s1="hello world";
        String[]strings=s1.split(" ");
        for (String s:strings){
            System.out.println(s);
        }
    }
    public static void main9(String[] args) {
        String s1="ababcabdeaf";
        String ret1=s1.replaceFirst("a","b");
        System.out.println(ret1);
        System.out.println("======");
        String ret2=s1.replace('a','o');
        System.out.println(ret2);

    }
    public static void main8(String[] args) {
        String s="Hello world";
        char[]chars=s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.print(chars[i]+" ");
        }
        String s1=String.format("%d-%d-%d",2000,1,1);
        System.out.println(s1);
    }
    public static void main7(String[] args) {
        String s1="HEllo";
        s1=s1.toLowerCase();
        System.out.println(s1);
        System.out.println("=========");
        String s2="hEllO";
        s2=s2.toUpperCase();
        System.out.println(s2);
    }
    public static void main6(String[] args) {
        String s1="10";
        String s2="20.4";
        String s3="false";
        int a=Integer.valueOf(s1);
        double b= Double.valueOf(s2);
        boolean c=Boolean.valueOf(s3);
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }
    public static void main5(String[] args) {
        int a=10;
        double b=20.6;
        boolean flg=true;
        String s1=String.valueOf(a);
        String s2=String.valueOf(b);
        String s3=String.valueOf(flg);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
    }
    public static void main4(String[] args) {
        String s="aabcabcddcba";
        //chatAt(i)返回i下标的字符
        for (int i=0;i<s.length();i++){
            System.out.print(s.charAt(i)+" ");
        }
        //indexof()
        int ret=s.indexOf('b');
        int ret1=s.indexOf("bc");
        int ret2=s.indexOf("b",4);
        int ret3=s.indexOf("dd",3);
        //lastIndexOf()从后往前找
        int ret4=s.lastIndexOf("d");
        int ret5=s.lastIndexOf('b');
        int ret6=s.lastIndexOf("cd",3);
        int ret7=s.lastIndexOf('c',4);
        System.out.println("======");
        System.out.print(ret+" ");
        System.out.print(ret1+" ");
        System.out.print(ret2+" ");
        System.out.print(ret3+" ");
        System.out.print(ret4+" ");
        System.out.print(ret5+" ");
        System.out.print(ret6+" ");
        System.out.print(ret7+" ");
    }
    public static void main3(String[] args) {
        String s="abcd";
        String s1="agada";
        int ret=s.compareTo(s1);
        System.out.println(ret);
        String s2="Admin";
        String s3="admin";
        int ret1=s2.compareToIgnoreCase(s3);
        System.out.println(ret1);
    }
    public static void main2(String[] args) {
        String str1=new String("hello");
        String str2=new String("hello");
        String str3=str1;
        System.out.println(str1==str2);
        System.out.println(str1==str3);
        System.out.println(str2==str3);
        System.out.println("===========");
        System.out.println(str1.equals(str2));
        System.out.println(str1.equals(str3));
        System.out.println(str2.equals(str3));
    }
    public static void main1(String[] args) {
        String str1="hello";
        String str2=new String(" world");
        char[]chars={'a','b','c','d'};
        String str3=new String(chars);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }
}